package com.core.db.condition;

/**
 * 默认sql排序封装类
 * 
 * @author 殷田
 *
 */
class DefaultOrder implements Order
{
	private StringBuffer buffer = new StringBuffer();

	@Override
	public String content()
	{
		return buffer.toString();
	}

	@Override
	public Order reset()
	{
		buffer = new StringBuffer();
		return this;
	}

	@Override
	public Order desc( String column )
	{
		addOrder( column, true );
		return this;
	}

	@Override
	public Order asc( String column )
	{
		addOrder( column, false );
		return this;
	}

	private synchronized void addOrder( String column, boolean desc )
	{
		String connector = buffer.length() == 0 ? "ORDER BY " : " ,";
		buffer.append( connector ).append( column ).append( desc ? " DESC" : " ASC" );
	}
}
